package com.inspectortime.domain.impl;

import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.inspectortime.common.PersistentEntityBase;
import com.inspectortime.domain.Property;
import com.inspectortime.domain.type.Address;
import com.inspectortime.domain.type.FoundationType;
import com.inspectortime.domain.type.PropertyType;

@Entity
@Table(name = "PROPERTY")
public class PropertyImpl extends PersistentEntityBase implements Property {

	private int constructionYear;

	private String crossStreet;

	private FoundationType foundationType;
	
	private double squareFeet;

	private float listedPrice;

	private Address location;

	private int numberOfAcUnits;

	private float numberOfBathrooms;

	private int numberOfBedrooms;

	private int numberOfStories;

	private boolean occupied;

	private PropertyType propertyType;

	private String subdivisionName;
	
	private String otherStructures;

	public String getOtherStructures() {
		return otherStructures;
	}

	public void setOtherStructures(String otherStructures) {
		this.otherStructures = otherStructures;
	}

	public PropertyImpl() {}
	
	public PropertyImpl(Address address) {
		this.location = address;
	}
	
	public String toString() {
		return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
	}


	@Basic
	public int getConstructionYear() {
		return constructionYear;
	}

	@Transient
	public int getAgeInYears() {
		Calendar cal = new GregorianCalendar();
		int year = cal.get(Calendar.YEAR);
		return year - this.getConstructionYear();
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#getCrossStreet()
	 */
	@Basic
	@Column( length = 100 )
	public String getCrossStreet() {
		return crossStreet;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#getFoundationType()
	 */
	public FoundationType getFoundationType() {
		return foundationType;
	}
	
	public PropertyType getPropertyType() {
		return propertyType;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#getListedPrice()
	 */
	@Basic
	public float getListedPrice() {
		return listedPrice;
	}

	@Embedded
	public Address getLocation() {
		return location;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#getNumberOfAcUnits()
	 */
	@Basic
	public int getNumberOfAcUnits() {
		return numberOfAcUnits;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#getNumberOfBathrooms()
	 */
	@Basic
	public float getNumberOfBathrooms() {
		return numberOfBathrooms;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#getNumberOfBedrooms()
	 */
	@Basic
	public int getNumberOfBedrooms() {
		return numberOfBedrooms;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#getNumberOfStories()
	 */
	@Basic
	public int getNumberOfStories() {
		return numberOfStories;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#getSubdivisionName()
	 */
	@Basic
	@Column( length = 100 )
	public String getSubdivisionName() {
		return subdivisionName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#getType()
	 */
	public PropertyType getType() {
		return propertyType;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#isOccupied()
	 */
	@Basic
	public boolean isOccupied() {
		return occupied;
	}

	public void setConstructionYear(int year) {
		constructionYear = year;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#setCrossStreet(java.lang.String)
	 */
	public void setCrossStreet(String street) {
		crossStreet = street;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#setFoundationType(com.inspectortime.domain.type.FoundationType)
	 */
	public void setFoundationType(FoundationType type) {
		foundationType = type;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#setListedPrice(float)
	 */
	public void setListedPrice(float price) {
		listedPrice = price;
	}

	public void setLocation(Address address) {
		this.location = address;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#setNumberOfAcUnits(int)
	 */
	public void setNumberOfAcUnits(int number) {
		numberOfAcUnits = number;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#setNumberOfBathrooms(int)
	 */
	public void setNumberOfBathrooms(float number) {
		numberOfBathrooms = number;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#setNumberOfBedrooms(int)
	 */
	public void setNumberOfBedrooms(int number) {
		numberOfBedrooms = number;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#setNumberOfStories(int)
	 */
	public void setNumberOfStories(int stories) {
		numberOfStories = stories;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#setOccupied()
	 */
	public void setOccupied(boolean occupied) {
		this.occupied = occupied;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#setSubdivisionName(java.lang.String)
	 */
	public void setSubdivisionName(String subdivisionName) {
		this.subdivisionName = subdivisionName;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.inspectortime.domain.Property#setType(com.inspectortime.domain.type.PropertyType)
	 */
	public void setType(PropertyType type) {
		propertyType = type;
	}

	public void setPropertyType(PropertyType propertyType) {
		this.propertyType = propertyType;
	}

	public double getSquareFeet() {
		return squareFeet;
	}

	public void setSuqreFeet(double squareFeet) {
		this.squareFeet = squareFeet;
	}

	public void setSquareFeet(double squareFeet) {
		this.squareFeet = squareFeet;
	}
}
